package com.oocl.reservedparkingsystembackend.service;

import com.oocl.reservedparkingsystembackend.mapper.ParkingLotMapper;
import com.oocl.reservedparkingsystembackend.model.dto.ParkingLotRequest;
import com.oocl.reservedparkingsystembackend.model.dto.ParkingLotResponse;
import com.oocl.reservedparkingsystembackend.model.entity.ParkingLot;
import com.oocl.reservedparkingsystembackend.repository.ParkingLotRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ParkingLotService {
    @Autowired
    private final ParkingLotRepository parkingLotRepository;
    @Autowired
    private final ParkingLotMapper parkingLotMapper;

    public ParkingLotService(ParkingLotRepository parkingLotRepository, ParkingLotMapper parkingLotMapper) {
        this.parkingLotRepository = parkingLotRepository;
        this.parkingLotMapper = parkingLotMapper;
    }

    public List<ParkingLotResponse> getAllParkingLot() {
        List<ParkingLot> parkingLotList = parkingLotRepository.findAll();
        List<ParkingLotResponse> parkingLotResponses = new ArrayList<>();
        for (ParkingLot parkingLot : parkingLotList) {
            parkingLotResponses.add(parkingLotMapper.toParkingLotResponse(parkingLot));
        }
        return parkingLotResponses;
//        ParkingLotResponse parkingLotResponse = new ParkingLotResponse("1",400,"南方软件园",16,"",new BigDecimal(100),1,"广东省珠海市香洲区唐家湾镇南方软件园","地上停车场");
//        ParkingLotResponse parkingLotWestResponse = new ParkingLotResponse("1",400,"南方软件园",16,"",new BigDecimal(100),1,"南方软件园西区香洲区唐家湾镇南方软件园","地上停车场");
//        List<ParkingLotResponse> parkingLotListResponse = new ArrayList<>();
//        parkingLotListResponse.add(parkingLotResponse);
//        parkingLotListResponse.add(parkingLotWestResponse);
//        return parkingLotListResponse;
    }

    public ParkingLotResponse addParkingLot(ParkingLotRequest parkingLotRequest){
        ParkingLot parkingLot = parkingLotMapper.toParkingLot(parkingLotRequest);
        ParkingLot parkingLotResult = parkingLotRepository.save(parkingLot);
        return parkingLotMapper.toParkingLotResponse(parkingLotResult);

    }

}
